import ufoCtrl from "./ufoCtrl";

const { ccclass, property } = cc._decorator;

@ccclass
export default class game extends cc.Component {

    //static readonly instance:game=new game();

    @property(cc.Node)
    gameReady: cc.Node = null;

    @property(cc.Node)
    bg: cc.Node = null;

    @property(cc.Node)
    gamePlaying: cc.Node = null;

    @property(cc.Node)
    gamePause: cc.Node = null;

    @property(cc.Node)
    gameOver: cc.Node = null;

    @property(cc.Node)
    bg1: cc.Node = null;

    @property(cc.Node)
    bg2: cc.Node = null;

    @property(cc.Node)
    hero: cc.Node = null;

    @property(cc.Prefab)
    bulletPre: cc.Prefab = null;

    @property(cc.Prefab)
    bulletPre2:cc.Prefab=null;

    @property(cc.Prefab)
    bulletPre3:cc.Prefab=null;


    @property(cc.Prefab)
    enemyPre1: cc.Prefab = null;

    @property(cc.Prefab)
    enemyPre2: cc.Prefab = null;

    @property(cc.Prefab)
    enemyPre3: cc.Prefab = null;

    @property(cc.Prefab)
    ufoPre1:cc.Prefab=null;

    @property(cc.Label)
    score:cc.Label=null;

    @property(cc.Label)
    lab_bestScore:cc.Label=null;

    @property(cc.Label)
    lastScore:cc.Label=null;

    @property(cc.Label)
    bestScore:cc.Label=null;

    @property(cc.Node)
    skifLayer:cc.Node;

    @property(cc.Node)
    startReadyBgm:cc.Node;

    

    // @property(cc.AudioClip)
    // bgm:cc.AudioClip=null
    @property({
        type: cc.AudioClip,// use 'type:' to declare Texture2D object directly
      })bgm

      @property({
        type: cc.AudioClip,// use 'type:' to declare Texture2D object directly
      })readyBgm

      @property({
        type: cc.AudioClip,// use 'type:' to declare Texture2D object directly
      })enemyDieSound
      @property({
        type: cc.AudioClip,// use 'type:' to declare Texture2D object directly
      })heroDieSound
      @property({
        type: cc.AudioClip,// use 'type:' to declare Texture2D object directly
      })ufoSound_1;


    
    bulletPool_0: cc.NodePool = null;
    bulletPool: cc.NodePool = null;
    bulletPool2: cc.NodePool = null;
    bulletPool3: cc.NodePool = null;
    enemyPool_1: cc.NodePool = null;
    enemyPool_2: cc.NodePool = null;
    enemyPool_3: cc.NodePool = null;
    ufoPool_1: cc.NodePool = null;

    

    isBgMove = false;

    gameType: number = 0;//游戏状态 0：ready状态   1:playing状态    2：pause状态   3: over

    builletTime: number = 0;

    enemyTime: number = 0;

    enemyTime2 = 5;

    ufoTime = 480;

    str: string = null;

    randomNum = [60, 90, 100];

    pos_enemy = cc.v2(0, 0);

    scoreNum=0;

    bestScoreNum;

    gameTime=0;
    
    isBgm=false;

    isReadyBgm=false;

    current

    readyCurrent 

    //static instance: ufoCtrl = null;

    Ufo_instance
      scc

     
   

    // LIFE-CYCLE CALLBACKS:

    onLoad() {
        
        this.bestScoreNum = cc.sys.localStorage.getItem('bestScore')
        if(this.bestScoreNum==null){
            this.bestScoreNum=0;
        }
        //this.lab_bestScore.string = cc.sys.localStorage.getItem("bestScore")
        this.bulletPool = new cc.NodePool();
        this.bulletPool_0 = new cc.NodePool();
        this.bulletPool2 = new cc.NodePool();
        this.bulletPool3 = new cc.NodePool();
        this.enemyPool_1 = new cc.NodePool();
        this.enemyPool_2 = new cc.NodePool();
        this.enemyPool_3 = new cc.NodePool();
        this.ufoPool_1 = new cc.NodePool();
        this.gameOver.active = false;
        this.scoreNum=0;
        this.addScore(0);
        //this.node.getComponent(cc.AudioSource).play();
        // this.current=cc.audioEngine.play(this.bgm,true,0.5)
        //this.playBgm();
        if(this.gameType==0){
            this.playReadyBgm();
        }
        
    }

    playUfoSound(){
        cc.audioEngine.play(this.ufoSound_1,false,1);
    }

    playReadyBgm(){
        if(this.isReadyBgm==false){
        this.isReadyBgm=true;
        this.readyCurrent =cc.audioEngine.play(this.readyBgm,true,0.5);
          console.log("play");
        }
    }

    stopReadyBgm(){
        cc.audioEngine.stop(this.readyCurrent);
        this.isReadyBgm=false
    }

    pauseReadyBgm(){
        cc.audioEngine.pause(this.readyCurrent);
        this.isReadyBgm=false
    }
        
       
    resumeReadyBgm(){
        cc.audioEngine.resume(this.readyCurrent);
        this.isReadyBgm=true
    }



    changeReadyBgm(){
                if(this.isReadyBgm){
                    this.changPic();
                    this.pauseReadyBgm()
                    //console.log("1");
                    
                }else if(this.isReadyBgm == false)
                    {
                    this.changPicBack();
                    this.resumeReadyBgm()
                    //console.log("2");
                    
                }
            }
        
            changPic(){
                let self = this
                cc.loader.loadRes("stop", cc.SpriteFrame, function (err, spriteFrame) {
                    self.startReadyBgm.children[0].getComponent(cc.Sprite).spriteFrame = spriteFrame;
                });
             }
        
        
             changPicBack(){
                let self = this
                cc.loader.loadRes("play", cc.SpriteFrame, function (err, spriteFrame) {
                    self.startReadyBgm.children[0].getComponent(cc.Sprite).spriteFrame = spriteFrame;
                });
             }
    

    playBgm(){
        if(this.isBgm==false){
        this.isBgm=true;
        this.current =cc.audioEngine.play(this.bgm,true,0.5);
          console.log("playBgm");
        }
    }
    

    stopBgm(){
            cc.audioEngine.stop(this.current);
            this.isBgm=false
        }


        pauseBgm(){
            cc.audioEngine.pause(this.current);
            
        }
            
           
        resumeBgm(){
            cc.audioEngine.resume(this.current);
        }
    start() {

        //console.log(599/300);
        
        // 开启碰撞检测系统，未开启时无法检测
        cc.director.getCollisionManager().enabled = true;
        // cc.director.getCollisionManager().enabledDebugDraw = true;


        //this.creatBullet();
        
        

        this.setTouch();
        //this.heroTouch();
        this.gameReady.active = true;
        this.gamePlaying.active = false;
        this.gamePause.active = false;

        this.gamePause.zIndex = 2;
        this.hero.zIndex = 2;
        this.gameOver.zIndex = 2;
        this.gamePlaying.zIndex = 2;

        // this.getComponent
        // console.log();
        // this.Ufo_instance = cc.instantiate(this.ufoPre1);
        // this.scc= this.Ufo_instance.getComponent(ufoCtrl)
        // this.scc=new ufoCtrl();
        
        //this.changUfo();
        
        
    }

    // onCollisionEnter(other,self){
    //     if(self.tag == 8&&other.tag == 10){
    //         self.hit();
            
    //         //console.log(this.isGet+" "+"ufoCtrl");
            
    //     }
        
    // }

   changUfo(){
    let Ufo=  cc.instantiate(this.ufoPre1);
    
    let dd = Ufo.getComponent(ufoCtrl)
    
    console.log(dd.isGet);
    
    
// let children = this.node.children;
// for (let i = children.length - 1; i >= 0; i--) {
//     let js = children[i].getComponent("ufoCtrl");
//     if (js) {
//         js.bian();
//         if(js.isDie){

//         }
//         //console.log(js.isDie);
        
//     }
// }
   }


    playSoundEnemyDie(){
        cc.audioEngine.play(this.enemyDieSound,false,1)
    }

    playSoundHeroDie(){
        cc.audioEngine.play(this.heroDieSound,false,1)
    }


    // stopBgm(send){
    //     if(send=="stop"){
    //         cc.audioEngine.stop(this.bgm)
    //         cc.audioEngine.stop(this.bgm);//停止之前播放的声音
    //         console.log("stopM");
            
    //     }
        
    // }
    addScore(ss){
        this.scoreNum =this.scoreNum+ss;
        this.score.string =""+this.scoreNum;
        if(this.bestScoreNum < this.scoreNum){
            this.bestScoreNum = this.scoreNum;
            cc.sys.localStorage.setItem('bestScore', this.bestScoreNum)
        }
        this.lab_bestScore.string = this.bestScoreNum+"";
    }

    gameOverOver() {
        this.skifLayer.active=false;
        this.gameOver.active = true;
        this.gamePause.active=false;
        this.lastScore.string = this.scoreNum+"";
        this.bestScore.string = cc.sys.localStorage.getItem('bestScore');
        //this.onBulletKilled(this.bulletPre);
        this.removeBullet();
    }
    creatB0() {
        let bullet0 = null;
        if (this.bulletPool_0.size() > 0) { // 通过 size 接口判断对象池中是否有空闲的对象
            bullet0 = this.bulletPool_0.get();
        } else { // 如果没有空闲对象，也就是对象池中备用对象不够时，我们就用 cc.instantiate 重新创建
            bullet0 = cc.instantiate(this.bulletPre);
        }
        bullet0.parent = this.node; // 将生成的敌人加入节点树
        let pos = this.hero.getPosition();
        bullet0.setPosition(pos.x, pos.y + this.hero.height / 2 + 5);
        //bullet.getComponent('Enemy').init(); //接下来就可以调用 enemy 身上的脚本进行初始化
    }
    
    //创建子弹  对象池(用)
    creatB() {
        let bullet = null;
        if (this.bulletPool.size() > 0) { // 通过 size 接口判断对象池中是否有空闲的对象
            bullet = this.bulletPool.get();
        } else { // 如果没有空闲对象，也就是对象池中备用对象不够时，我们就用 cc.instantiate 重新创建
            bullet = cc.instantiate(this.bulletPre);
        }
        bullet.parent = this.node; // 将生成的敌人加入节点树
        let pos = this.hero.getPosition();
        bullet.setPosition(pos.x, pos.y + this.hero.height / 2 + 5);
        //bullet.getComponent('Enemy').init(); //接下来就可以调用 enemy 身上的脚本进行初始化
    }

    creatB2() {
        let bullet2 = null;
        if (this.bulletPool2.size() > 0) { // 通过 size 接口判断对象池中是否有空闲的对象
            bullet2 = this.bulletPool2.get();
        } else { // 如果没有空闲对象，也就是对象池中备用对象不够时，我们就用 cc.instantiate 重新创建
            bullet2 = cc.instantiate(this.bulletPre2);
        }
        bullet2.parent = this.node; // 将生成的敌人加入节点树
        let pos = this.hero.getPosition();
        bullet2.setPosition(pos.x-10, pos.y + this.hero.height / 2 + 5);
        //bullet.getComponent('Enemy').init(); //接下来就可以调用 enemy 身上的脚本进行初始化
    }

    creatB3() {
        let bullet3 = null;
        if (this.bulletPool3.size() > 0) { // 通过 size 接口判断对象池中是否有空闲的对象
            bullet3 = this.bulletPool3.get();
        } else { // 如果没有空闲对象，也就是对象池中备用对象不够时，我们就用 cc.instantiate 重新创建
            bullet3 = cc.instantiate(this.bulletPre3);
        }
        bullet3.parent = this.node; // 将生成的敌人加入节点树
        let pos = this.hero.getPosition();
        bullet3.setPosition(pos.x+10, pos.y + this.hero.height / 2 + 5);
        //bullet.getComponent('Enemy').init(); //接下来就可以调用 enemy 身上的脚本进行初始化
    }

    creatUfo() {
        let Ufo = null;
        let pos_ufo = cc.v2(0, 0);
        if (this.ufoPool_1.size() > 0) { // 通过 size 接口判断对象池中是否有空闲的对象
            Ufo = this.ufoPool_1.get();
        } else { // 如果没有空闲对象，也就是对象池中备用对象不够时，我们就用 cc.instantiate 重新创建
            Ufo = cc.instantiate(this.ufoPre1);
        }
        Ufo.parent = this.node; // 将生成的敌人加入节点树
        // let pos = this.hero.getPosition();
        let js = Ufo.getComponent("ufoCtrl");
        //let kl=js.reGet();
        //console.log(kl);
        
        // if(js.isGet==true){
        //     console.log("yes");
            
        // }
        // console.log(js.isGet);
        if (js) {
            js.init();
        }
        // let scc=Ufo.getComponent(ufoCtrl);
        // scc.reIsGet = ()=>{
        //     return scc.isGet;
        // }
       
        
        
        pos_ufo.x = -210 + Math.random() * 420;
        pos_ufo.y = 520;
        Ufo.setPosition(pos_ufo);
       
       
        //bullet.getComponent('Enemy').init(); //接下来就可以调用 enemy 身上的脚本进行初始化
    }

    //创建敌机  对象池(用)
    creatEnemy(enemyType) {
        let enemy = null;
        let pos_enemy = cc.v2(0, 0);
        if (enemyType == 1) {
            if (this.enemyPool_1.size() > 0) { // 通过 size 接口判断对象池中是否有空闲的对象
                enemy = this.enemyPool_1.get();
            } else { // 如果没有空闲对象，也就是对象池中备用对象不够时，我们就用 cc.instantiate 重新创建
                enemy = cc.instantiate(this.enemyPre1);
            }
            this.str = "enemyCtrl";
            pos_enemy.x = -210 + Math.random() * 420;
            pos_enemy.y = 520;
        } else if (enemyType == 2) {
            if (this.enemyPool_2.size() > 0) { // 通过 size 接口判断对象池中是否有空闲的对象
                enemy = this.enemyPool_2.get();
            } else { // 如果没有空闲对象，也就是对象池中备用对象不够时，我们就用 cc.instantiate 重新创建
                enemy = cc.instantiate(this.enemyPre2);
            }
            this.str = "enemyCtrl_2";
            pos_enemy.x = -200 + Math.random() * 400;
            pos_enemy.y = 530;
        } else if (enemyType == 3) {
            if (this.enemyPool_3.size() > 0) { // 通过 size 接口判断对象池中是否有空闲的对象
                enemy = this.enemyPool_3.get();
            } else { // 如果没有空闲对象，也就是对象池中备用对象不够时，我们就用 cc.instantiate 重新创建
                enemy = cc.instantiate(this.enemyPre3);
            }
            this.str = "enemyCtrl_3";
            pos_enemy.x = -150 + Math.random() * 300;
            pos_enemy.y = 570;
        }
        enemy.parent = this.node; // 将生成的敌人加入节点树
        let js = enemy.getComponent(this.str);
        if (js) {
            js.init();
        }
        enemy.setPosition(pos_enemy);
        //let pos = cc.v2(Math.random()*400-200,450);
        //console.log(cc.winSize.height);      

        //enemy.getComponent('Enemy').init(); //接下来就可以调用 enemy 身上的脚本进行初始化
    }

    //子弹出屏销毁
    onBulletKilled(bullet) {
        // enemy 应该是一个 cc.Node
        this.bulletPool.put(bullet); // 和初始化时的方法一样，将节点放进对象池，这个方法会同时调用节点的 removeFromParent
        console.log("no");
        
    }

    onBullet2Killed(bullet2) {
        // enemy 应该是一个 cc.Node
        this.bulletPool2.put(bullet2); // 和初始化时的方法一样，将节点放进对象池，这个方法会同时调用节点的 removeFromParent
    }

    onBullet3Killed(bullet3) {
        // enemy 应该是一个 cc.Node
        this.bulletPool3.put(bullet3); // 和初始化时的方法一样，将节点放进对象池，这个方法会同时调用节点的 removeFromParent
    }


    onUfoKilled(Ufo) {
        // enemy 应该是一个 cc.Node
        this.ufoPool_1.put(Ufo); // 和初始化时的方法一样，将节点放进对象池，这个方法会同时调用节点的 removeFromParent
    }

    onEnemyKilled(enemy, enemyType) {
        // enemy 应该是一个 cc.Node
        if (enemyType == 1) {
            this.enemyPool_1.put(enemy); // 和初始化时的方法一样，将节点放进对象池，这个方法会同时调用节点的 removeFromParent
        } else if (enemyType == 2) {
            this.enemyPool_2.put(enemy); // 和初始化时的方法一样，将节点放进对象池，这个方法会同时调用节点的 removeFromParent
        } else if (enemyType == 3) {
            this.enemyPool_3.put(enemy); // 和初始化时的方法一样，将节点放进对象池，这个方法会同时调用节点的 removeFromParent
        }

    }

    removeUfo() {
        let children = this.node.children;
        for (let i = children.length - 1; i >= 0; i--) {
            let js = children[i].getComponent("ufoCtrl");
            if (js) {
                this.onUfoKilled(children[i]);
            }
        }
    }

    //移除子弹(暂停和回到主页)
    removeBullet() {
        let children = this.node.children;
        for (let i = children.length - 1; i >= 0; i--) {
            let js = children[i].getComponent("bulletCtrl");
            if (js) {
                this.onBulletKilled(children[i]);
            }
        }
    }

    //移除子弹(暂停和回到主页)
    removeBullet2() {
        let children = this.node.children;
        for (let i = children.length - 1; i >= 0; i--) {
            let js = children[i].getComponent("bulletCtrl_2");
            if (js) {
                this.onBulletKilled(children[i]);
            }
        }
    }

    //移除子弹(暂停和回到主页)
    removeBullet3() {
        let children = this.node.children;
        for (let i = children.length - 1; i >= 0; i--) {
            let js = children[i].getComponent("bulletCtrl_3");
            if (js) {
                this.onBulletKilled(children[i]);
            }
        }
    }
    //移除敌人(暂停和回到主页)
    removeEnemy() {
        let children = this.node.children;
        for (let i = children.length - 1; i >= 0; i--) {
            if (children[i].getComponent("enemyCtrl")) {
                this.onEnemyKilled(children[i], 1);
            } else if (children[i].getComponent("enemyCtrl_2")) {
                this.onEnemyKilled(children[i], 2);
            } else if (children[i].getComponent("enemyCtrl_3")) {
                this.onEnemyKilled(children[i], 3);
            }
        }
    }


    //创建子弹  计时器(没用到)
    creatBullet() {
        this.schedule(() => {
            //创建子弹
            let bullet = cc.instantiate(this.bulletPre);
            //设置父物体

            bullet.setParent(this.node);
            bullet.x = this.hero.x;
            bullet.y = this.hero.y + 80;
        }, 0.2);
    }

    //开始游戏按钮
    setTouch() {
        this.node.on('touchstart', function (event) {
            //console.log("ssss"+this.gameType);

            if (this.gameType == 0) {
                this.gameType = 1;
                //console.log("ccc"+this.gameType);

            }
            //console.log("touchstart");
            this.gameReady.active = false;
            this.gamePlaying.active = true;
            this.isBgMove = true;
            if(this.gameType==1){
                this.stopReadyBgm();
            }
            if(this.gameType==1){
                this.playBgm();
                console.log("点击了屏幕");
                
            }
            //this.node.getComponent(cc.AudioClip).play();
            

        }, this);
        this.hero.on('touchmove', function (event) {
            let pos_hero = this.hero.getPosition();
            let pso_move = event.getDelta();
            this.hero.setPosition(cc.v2(pos_hero.x + pso_move.x, pos_hero.y + pso_move.y));
            //this.hero.setPosition(event.getLocation());
            // let poss = this.hero.getPosition();
            // console.log(poss);
            //console.log("touchmove");
        }, this);
        // if(this.hero.active==false){
        //     this.node.off('touchmove');
        // }
        this.node.on('touchend', function (event) {
            // let bullet = cc.instantiate(this.bulletPre);
            // //设置父物体

           
        }, this);

        this.skifLayer.on("touchstart",(event)=>{
            this.skifLayer.active=false;
        },this)

        let skifList = this.skifLayer.children[0].children;
        for (let i = 0; i < skifList.length; i++) {
           skifList[i].on("touchstart",(event)=>{
            this.changSkif(i);
           },this);
            
        }
    }
    //修改皮肤
    changSkif(j){
        let bgList = this.bg.children;  //获取背景子节点
        let color = [
            [116,208,38],
            [8,138,107],
            [138,13,8],
            [8,117,138],
            [142,32,100],
            [255,255,255]
        ];
        for (let i = 0; i < bgList.length; i++) {
            bgList[i].runAction(cc.tintTo(2,color[j][0],color[j][1],color[j][2]))
            
        }
        //节点遍历
        
    }

    //点击事件
    clickBtn(sender, str) {
        if (str == "pause") {
            //this.gameReady.active = false;
            this.gamePause.active = true;
            cc.log("点击了暂停按钮");
            this.gameType = 2
        } else if (str == "continue") {
            this.gamePause.active = false;
            //this.gamePlaying.active = true;
            cc.log("点击了继续按钮");
            this.gameType = 1;
        } else if (str == "restart") {
            this.gamePause.active = false;
            this.gameOver.active = false;
            //this.gamePlaying.active=true;
            cc.log("点击了重开按钮");
            this.gameTime=0;
            this.scoreNum=0;
            this.addScore(0);
            let js = this.hero.getComponent("hero");
            if (js) {
                js.init();
            }
            this.gameType = 1;
            this.removeBullet();
            this.removeBullet2();
            this.removeBullet3();
            this.removeEnemy();
            this.removeUfo();
            this.hero.setPosition(cc.v2(0, -290));

        } else if (str == "backHome") {
            cc.log("点击了回到主页按钮");
            this.stopBgm();
            this.playReadyBgm();
            this.gameTime=0;
            this.gameType=0;
            this.scoreNum=0;
            this.addScore(0);
            this.gameOver.active = false;
            let js = this.hero.getComponent("hero");
            if (js) {
                js.init();
            }
            this.gamePause.active = false;
            this.gamePlaying.active = false;
            this.gameReady.active = true;
            this.isBgMove = false;
            this.gameType = 0;
            this.removeBullet();
            this.removeBullet2();
            this.removeBullet3();
            this.removeEnemy();
            this.removeUfo();
            this.hero.setPosition(cc.v2(0, -290));
        }
        else if(str=="change"){
            cc.log("点击换肤")
            this.skifLayer.active=true;
        }
        // else if(str =="stop"){
        //     // cc.audioEngine.stop(this.current);//停止之前播放的声音
        //     this.pauseBgm();
        //     console.log("stopMus"); 
        // }else if(str == "play"){
        //     this.resumeBgm();
        // }
    }

    //屏幕移动方法
    setBG() {
        this.bg1.y = this.bg1.y - 3;
        this.bg2.y = this.bg2.y - 3;
        if (this.bg1.y <= -this.bg1.height) {
            this.bg1.y = this.bg2.y + this.bg1.height;
        }
        if (this.bg2.y <= -this.bg1.height) {
            this.bg2.y = this.bg1.y + this.bg1.height;
        }
    }
    // for (let bgNode of this.bg.children) {
    //     bgNode.y -= 1;
    //     if (bgNode.y < -bgNode.height) {
    //         bgNode.y += (bgNode.height) * 2;
    //     }

    setBg2(dt){
            for (let bgNode of this.bg.children) {
        //移动
        bgNode.y -= 300 * dt;
        if (bgNode.y <= -this.bg1.height*2) {
            bgNode.y += this.bg1.height *4;
        }
    }
    }
    // for (let bgNode of this.bg.children) {
    //     //移动
    //     bgNode.y -= 100 * dt;
    //     if (bgNode.y <= -this.bg1.height) {
    //         bgNode.y += this.bg1.height * 2;
    //     }
    // }

    // cUfo(){
    //    this.schedule(this.creatUfo,1)
    // }

    update(dt) {
        

        //创建道具
        this.ufoTime--;
        if(this.ufoTime==0){
            this.ufoTime=480;
            if(this.gameType == 1 || this.gameType == 3){
                this.creatUfo();
                console.log("ufo");
            }
        }
        
       

        if (this.isBgMove) {
            if (this.gameType == 1) {
                this.setBg2(dt);
            }
        }

        //发射子弹
        this.builletTime++
        if (this.builletTime == 12) {
            this.builletTime = 0;
            if (this.gameType == 1) {
                this.creatB0(); 
               
                // let Ufo=  cc.instantiate(this.ufoPre1);
                // let gg = cc.find("Canvas/ufo1");
                // let sc = gg.getComponent("ufoCtrl");
                // let dd = Ufo.getComponent(ufoCtrl)
                // console.log(dd.isGet);
                //console.log(ufoCtrl.isok);
                
                
                // if(dd.isGet==true){
                //     console.log("yes");
                    
                // }
            }
        }

        
        //随着时间增大，5秒一次创建敌机数从[1,5]上升到[1，20]
        let randomNumEnemy =5;
        if(this.gameType==1){
            this.gameTime++;
            if(this.gameTime%300==0){
                randomNumEnemy+= Math.round(this.gameTime/300);
                if(randomNumEnemy>20){
                    randomNumEnemy=20;
                }
            }
            //敌机出现的概率，从[60,90,100]到[40,75,100]
            this.randomNum[0]-=this.randomNum[0]-2
            this.randomNum[1]-=this.randomNum[1]-1
            if(this.randomNum[0]<40){
                this.randomNum[0]=40
            }
            if(this.randomNum[1]<75){
                this.randomNum[1]=75;
            }
        }
        //随机创建敌机1,2,3
        this.enemyTime++
        if (this.enemyTime == 120) {//2秒一次
            this.enemyTime = 0;
            let num_random = Math.floor(Math.random() * randomNumEnemy) + 1;  //产生的范围是[1，6)到[1,21);
            for (let i = 0; i < num_random; i++) {//2秒产生1到5台敌机，随着时间增长，产生[1到20]台敌机
                if (this.gameType == 1 || this.gameType == 3) {
                    let num = Math.random() * 100
                    if (num < this.randomNum[0]) {
                        this.creatEnemy(1);
                    } else if (num < this.randomNum[1]) {
                        this.creatEnemy(2);
                    } else if (num < this.randomNum[2]) {
                        this.creatEnemy(3);
                        //console.log("enemy3");
                    }
                }

            }

        }

       
        


    }
}
